// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// k [author] rhyme_lph
// S [email]  rhymelph@gmail.com
// S [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/src/common/config.dart';
import 'package:finance_app/src/entities/credit_note_entity.dart';
import 'package:finance_app/src/http_service/http_credit_note_service.dart';
import 'package:finance_app/src/mixin/check_plan_mixin.dart';
import 'package:finance_app/src/mixin/search_data_list_mixin.dart';
import 'package:finance_app/src/router_gen/router_gen_providers.dart';
import 'package:finance_app/src/widgets/bottom_sheet/delete_info_bottom_sheet.dart';
import 'package:flutter/material.dart';
import 'package:finance_app/src/page/dashboard/credit_note/credit_note_number_page.dart';

class CreditNoteNumberProvider extends BaseProvider<List<CreditNoteEntity>>
    with SearchDataListMixin<List<CreditNoteEntity>>, CheckPlanMixin {
  CreditNoteEntity currentSelect;

  @override
  Future get dataFuture => HttpCreditNoteService.creditNoteList();

  void onNavAddCreditNote() async {
    if (isPlanExpired()) return;
    final result =
        await Routes.navigateTo(RouterGenProviders.newCreditNotePage, params: {
      'isSelectMode': true,
    });
    if (result != null) {
      onSelect(result);
    }
  }

  void onSelect(CreditNoteEntity item1) {
    if (currentSelect == item1) return;

    currentSelect = item1;
    obtainContext?.call((context) {
      Navigator.of(context).pop(currentSelect);
    });
  }

  @override
  void searchRefreshData(data) {}
}
